package com.oocl.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;

import com.oocl.dao.MerchantsDao;
import com.oocl.dao.OrderCommentDao;
import com.oocl.dao.OrdersDao;
import com.oocl.dao.base.BaseDao;
import com.oocl.entity.Clients;
import com.oocl.entity.DeliverInfo;
import com.oocl.entity.Merchants;
import com.oocl.entity.OrderComment;
import com.oocl.entity.Orders;
import com.oocl.service.OrderCommentService;

@Service("orderCommentService")
public class OrderCommentServiceImpl implements OrderCommentService {

	@Resource(name="orderCommentDao")
	private OrderCommentDao orderCommentDao;
	
	@Resource(name="baseDao")
	private BaseDao baseDao;
	
	@Resource(name="merchantsDao")
	private MerchantsDao merchantsDao;
	
	@Resource(name="ordersDao")
	private OrdersDao ordersDao;

	/*
	 * @Method:addOrderComment
	 * @function: insert order comment info to db
	 * @param:String icnum, String cid,String comment, String oclevel,String oid
	 * @Author:Wendy
	 * @time:2017-8-13
	 * 
	 */
	@Override
	@Transactional
	public OrderComment addOrderComment(String icnum, String cid,
			String comment, double oclevel,String oid) {
		// TODO Auto-generated method stub
		OrderComment oc=new OrderComment();
		Clients client=new Clients();
		client=(Clients)baseDao.find(Clients.class, cid);
		
		Merchants m=new Merchants();
		m=merchantsDao.findmerchantsByIcnum(icnum);
		
		oc.setOid(oid);
		oc.setClient(client);
		oc.setMerchant(m);
		oc.setComments(comment);
		oc.setOclevel(oclevel);
		oc.setCtime(new Date());
		oc.setStatus("0");
		
		baseDao.persist(oc);
		return oc;
	}

	/*
	 * @Method:loadOrderCommentByOid
	 * @function: find the comment info of the specific order
	 * @param:String oid
	 * @Author:Wendy
	 * @time:2017-8-13
	 * 
	 */
	@Override
	@Transactional
	public OrderComment loadOrderCommentByOid(String oid) {
		// TODO Auto-generated method stub
		OrderComment oc=new OrderComment();
		oc=orderCommentDao.findByOid(oid);
		return oc;
	}
	
}
